<template>
	<view class="p-10">
		<u-collapse :value="showMoreKeys" ref="collapse">
			<u-collapse-item :name="1">
				<template #title>
					<view class="content-item-title"><text class="title-txt">重点监控</text></view>
				</template>
				<my-play-video-list :list="['f68484807c2642c5bb2a73dca0befe84',
						'458b63988e424e28b773e45a0d90ad23']" @DataQuery="()=>collapse.init()" />
			</u-collapse-item>

			<up-subsection class="m-t-10" :list="[{name:'1#车间'},{name:'2#车间'}]" :current="current" mode="subsection"
				@change="(i)=>{current=i;getServerData()}"></up-subsection>

			<template v-for="(type,i) in typeList" :key="type.name + i">
				<u-collapse-item :name="i">
					<template #title>
						<view class="content-item-title"><text class="title-txt">{{type.name}}</text></view>
					</template>
					<my-grid :list="current == 0 ? list[type.name] : list1[type.name]" decimals="2" :col="2"></my-grid>
				</u-collapse-item>
			</template>
		</u-collapse>
		<up-back-top :scroll-top="scrollTop" />
	</view>
</template>

<script setup>
	/************************返回顶部*********************/
	const scrollTop = ref(0);
	onPageScroll((e) => {
		scrollTop.value = e.scrollTop;
	})

	import {
		getApiFabric,
	} from "@/api/customApi";

	const collapse = ref(null),
		showMoreKeys = ref([0, 1, 2, 3, 4, 5]),
		current = ref(0),
		typeList = [{
			name: '总控',
			value: 'STM-PSZYCJ-ZKZ',
			value1: 'STM-PSZECJ-ZKZ',
		}, {
			name: '破碎机A',
			value: 'STM-PSZYCJ-PSJA',
			value1: 'STM-PSZECJ-PSJA'
		}, {
			name: '破碎机B',
			value: 'STM-PSZYCJ-PSJB',
			value1: 'STM-PSZECJ-PSJB',
		}, {
			name: '板式给料机',
			value: 'STM-PSZYCJ-BSGLJ',
			value1: 'STM-PSZECJ-BSGLJ',

		}, {
			name: '皮带机',
			value: 'STM-PSZYCJ-PDJ',
			value1: 'STM-PSZECJ-PDJ',
		}],

		list = ref({
			'总控': [{
					key: 'ZKZ_PSZYXZT',
					title: '破碎站运行状态',
					value: '正常',
				}, {
					key: 'ZKZ_BDYCXZ',
					title: '本地远程',
					value: '远程',
				}, {
					key: 'ZKZ_FCYJCSJZ',
					title: '粉尘仪监测实际值',
					value: '',
					unit: '',
				}, {
					key: 'ZKZ_LDGD',
					title: '料斗高度',
					value: '',
					unit: ''
				}, {
					key: 'ZKZ_PLSX',
					title: '频率上限',
					value: '',
					unit: ""
				}, {
					key: 'ZKZ_1_HLD',
					title: '1#红绿灯',
					value: '',
					unit: '',
				}, {
					key: 'ZKZ_2_HLD',
					title: '2#红绿灯',
					value: '',
					unit: '',
				},
				{
					key: 'ZKZ_1SFBMC',
					title: '1S方波脉冲',
					value: '',
					unit: '',
				},
			],
			'破碎机A': [{
				key: 'YCJPSJ_YXXH',
				title: '运行信号',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_JSJWDXH',
				title: '减速机温度信号',
				value: 0,
				unit: '',
			}, {
				key: 'YCJPSJ_DJWDDBJ',
				title: '电机温度低报警',
				value: '',
			}, {
				key: 'YCJPSJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0,
			}, {
				key: 'YCJPSJ_DJZDDBJ',
				title: '电机震动低报警',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_DJZDGBJ',
				title: '电机震动高报警',
				value: '',
			}, {
				key: 'YCJPSJ_DLSJZ',
				title: '电流实际值',
				value: 0,
				unit: '',
			}, {
				key: 'YCJPSJ_HZXH',
				title: '合闸信号',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_YBGZXH',
				title: '油泵故障信号',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_YBYXXH',
				title: '油泵运行信号',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_ZBGZXH',
				title: '综保故障信号',
				value: '',
				unit: '',
			}],
			'破碎机B': [{
				key: 'YCJPSJ_YXXH',
				title: '运行信号',
				value: '',
			}, {
				key: 'YCJPSJ_JSJWDXH',
				title: '减速机温度信号',
				value: 0,
				unit: '',
			}, {
				key: 'YCJPSJ_DJWDDBJ',
				title: '电机温度低报警',
				value: '',
			}, {
				key: 'YCJPSJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0,
			}, {
				key: 'YCJPSJ_DJZDDBJ',
				title: '电机震动低报警',
				value: '',
				unit: '',
			}, {
				key: 'YCJPSJ_DJZDGBJ',
				title: '电机震动高报警',
				value: '',
			}, {
				key: 'YCJPSJ_DLSJZ',
				title: '电流实际值',
				value: 0,
				unit: '',
			}, {
				key: 'YCJPSJ_HZXH',
				title: '合闸信号',
				value: '',
			}, {
				key: 'YCJPSJ_YBGZXH',
				title: '油泵故障信号',
				value: '',
			}, {
				key: 'YCJPSJ_YBYXXH',
				title: '油泵运行信号',
				value: '',
			}],
			'板式给料机': [{
				key: 'BSGLJ_BPDLSJZ',
				title: '变频电流实际值',
				value: 0,
				unit: '',
			}, {
				key: 'BSGLJ_BPPLSJZ',
				title: '变频频率实际值',
				value: 0,
				unit: '',
			}, {
				key: 'BSGLJ_DJWDSJZ',
				title: '电机温度实际值',
				value: 0,
				unit: '',
			}, {
				key: 'BSGLJ_DJWDDBJ',
				title: '电机温度低报警',
				value: '',
			}, {
				key: 'BSGLJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
				unit: '',
			}, {
				key: 'BSGLJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0,
				unit: '',
			}, {
				key: 'BSGLJ_DJZDDBJ',
				title: '电机震动低报警',
				value: '',
				unit: '',
			}, {
				key: 'BSGLJ_DJZDGBJ',
				title: '电机震动高报警',
				value: '',
				unit: '',
			}],
			'皮带机': [{
				key: 'YCJPDJ_YXXH',
				title: '运行信号',
				value: '',
			}, {
				key: 'YCJPDJ_4_JSJWDXH',
				title: '4#减速机温度信号',
				value: 0,
			}, {
				key: 'YCJPDJ_DHXH',
				title: '打滑信号',
				value: '',
			}, {
				key: 'YCJPDJ_DLXH',
				title: '堵料信号',
				value: '',
			}, {
				key: 'YCJPDJ_HZXH',
				title: '合闸信号',
				value: '',
			}, {
				key: 'YCJPDJ_ZBGZXH',
				title: '综保故障信号',
				value: '',
			}, {
				key: 'YCJPDJ_ZSXH',
				title: '纵撕信号',
				value: '',
			}, {
				key: 'YCJPDJ_RQGZXH',
				title: '软启故障信号',
				value: '',
			}],
		}),
		list1 = ref({
			'总控': [{
				key: 'ZKZ_PSZYXZT',
				title: '破碎站运行状态',
				value: '',
				unit: '',
			}, {
				key: 'ZKZ_BDYCXZ',
				title: '本地远程',
				value: '',
			}, {
				key: 'ZKZ_FCYJCSJZ',
				title: '粉尘仪监测实际值',
				value: '',
				unit: '',
			}, {
				key: 'ZKZ_LDGD',
				title: '料斗高度',
				value: '',
				unit: ''
			}, {
				key: 'ZKZ_PLSX',
				title: '频率上限',
				value: '',
				unit: ""
			}, {
				key: 'ZKZ_1_HLD',
				title: '1#红绿灯',
				value: '',
				unit: '',
			}, {
				key: 'ZKZ_2_HLD',
				title: '2#红绿灯',
				value: '',
				unit: '',
			}, {
				key: 'ZKZ_1SFBMC',
				title: '1S方波脉冲',
				value: '',
				unit: '',
			}, ],
			'破碎机A': [{
				key: 'ECJPSJ_DJWDSJZ',
				title: '电机温度实际值',
				value: '',
			}, {
				key: 'ECJPSJ_DJWDDBJ',
				title: '电机温度低报警',
				value: '',
			}, {
				key: 'ECJPSJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
				unit: '',
			}, {
				key: 'ECJPSJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0
			}, {
				key: 'ECJPSJ_DJZDDBJ',
				title: '电机震动低报警',
				value: '',
				unit: '',
			}, {
				key: 'ECJPSJ_DJZDGBJ',
				title: '电机震动高报警',
				value: 0,
			}, {
				key: 'ECJPSJ_DJDLSJZ',
				title: '电流实际值',
				value: 0,
				unit: '',
			}, {
				key: 'ECJPSJ_JSJJRYX',
				title: '减速机加热运行',
				value: '',
				unit: '',
			}, {
				key: 'ECJPSJ_JSJJRGZ',
				title: '减速机加热故障',
				value: '',
				unit: '',
			}, {
				key: 'ECJPSJ_DJFZGZ',
				title: '电机反转故障',
				value: '',
				unit: '',
			}, {
				key: 'ECJPSJ_DJZZGZ',
				title: '电机正转故障',
				value: '',
				unit: '',
			}],
			'破碎机B': [{
				key: 'ECJPSJ_DJWDSJZ',
				title: '电机温度实际值',
				value: '',
			}, {
				key: 'ECJPSJ_DJWDDBJ',
				title: '电机温度低报警',
				value: '',
			}, {
				key: 'ECJPSJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
			}, {
				key: 'ECJPSJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0,
			}, {
				key: 'ECJPSJ_DJWDGBJ',
				title: '电机震动低报警',
				value: '',
			}, {
				key: 'ECJPSJ_DJZDGBJ',
				title: '电机震动高报警',
				value: '',
			}, {
				key: 'ECJPSJ_DJZDSJZ',
				title: '电流实际值',
				value: 0,
			}, {
				key: 'ECJPSJ_JSJJRYX',
				title: '减速机加热运行',
				value: '',
			}, {
				key: 'ECJPSJ_JSJJRYX',
				title: '减速机加热故障',
				value: '',
			}, {
				key: 'ECJPSJ_DJFZGZ',
				title: '电机反转故障',
				value: '',
			}, {
				key: 'ECJPSJ_DJZZGZ',
				title: '电机正转故障',
				value: '',
			}],
			'板式给料机': [{
				key: 'BSGLJ_BPDLSJZ',
				title: '变频电流实际值',
				value: 0,
			}, {
				key: 'BSGLJ_BPPLSJZ',
				title: '变频频率实际值',
				value: 0,
			}, {
				key: 'BSGLJ_DJWDSJZ',
				title: '电机温度实际值',
				value: 0,

			}, {
				key: 'BSGLJ_DJWDDBJ',
				title: '电机温度低报警',
			}, {
				key: 'BSGLJ_DJWDGBJ',
				title: '电机温度高报警',
				value: '',
			}, {
				key: 'BSGLJ_DJZDSJZ',
				title: '电机震动实际值',
				value: 0,
			}, {
				key: 'BSGLJ_DJZDDBJ',
				title: '电机震动低报警',
				value: '',
				unit: '',
			}, {
				key: 'BSGLJ_DJZDGBJ',
				title: '电机震动高报警',
				value: '',
				unit: '',
			}],
			'皮带机': [{
				key: 'ERJPDJ_DJYX',
				title: '电机运行',
				value: '',
			}, {
				key: 'ERJPDJ_CW',
				title: '超温',
				value: 0,
			}, {
				key: 'ERJPDJ_DJGZ',
				title: '电机故障',
				value: '',
			}, {
				key: 'ERJPDJ_DJJK',
				title: '电机集控',
				value: '',
			}, {
				key: 'ERJPDJ_DJJRGZ',
				title: '电机加热故障',
				value: '',
			}, {
				key: 'ERJPDJ_DJJRJK',
				title: '电机加热集控',
				value: '',
			}, {
				key: 'ERJPDJ_DJJRYX',
				title: '电机加热运行',
				value: '',
			}, {
				key: 'ERJPDJ_DL',
				title: '电流',
				value: '',
			}, {
				key: 'ERJPDJ_DM',
				title: '堵煤',
				value: '',
			}, {
				key: 'ERJPDJ_WD',
				title: '撕裂',
				value: '',
			}]
		});

	function fn() {
		typeList.forEach((item, i) => {
			getApiFabric({
				apiCode: "bdc47fc8-4942-453c-9d87-9ad64816429e",
				params: [{
					code: "deviceKeies",
					value: current.value == 0 ? item.value : item.value1
				}],
				propertyMapping: {
					key: "name",
					val: "value"
				}
			}).then((res) => {
				const resData = ArrayToObj(res.data);
				const data = current.value == 0 ? list : list1;
				data.value[item.name].forEach(item => {
					if (resData[item.key]) {
						item.value = resData[item.key]
						// 本地远程
						// if (item.key === 'ZKZ_BDYCXZ') {
						// 	switch (item.value) {
						// 		case 'false':
						// 			item.value = '本地';
						// 			break;
						// 		case 'true':
						// 			item.value = '远程';
						// 			break;
						// 	}
						// }
					} else {
						item.show = false
					}
				})
				nextTick(() => {
					collapse.value.init()
				})
			});
		})
	}

	function getServerData(refresh) {
		Promise.all([fn()]).then(() => {
			if (refresh) {
				nextTick(() => {
					uni.stopPullDownRefresh()
				})
			}
		});
	}

	onShow(() => {
		getServerData()
	})

	onPullDownRefresh(() => {
		getServerData(true)
	})
</script>

<style lang="scss" scoped>
</style>